<template>
  <el-card class="m-2 user-add">
    <avue-form v-model="form" :option="option" @submit="handleSubmit" />
  </el-card>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import userAddOption from "./avue-options";
import router from "@/router";
import { UserModel } from "@/model/user-model";
import UserAPI from "@/api/user";

defineOptions({
  name: "UserAdd",
});

const form = ref<UserModel>({
  mobile: "13320098527",
  name: "chen",
  sex: "男",
  domiciles: ["江西省", "萍乡市", "安源区"],
  id_card: "430682199909091111",
  birthday: "1999-09-09",
  address_citys: ["江西省", "萍乡市", "安源区"],
  address_detail: "113.825882,27.647687,江西省萍乡市安源区青山镇城西公交客运站(水口)(公交站)",
  family_situation: "12312312",
  house_situation: "自有",
  family_number: 1,
  elderly_number: 1,
  family_contact: "chen",
  family_contact_phone: "13320098527",
  identity_characteristics: "分散供养特困老年人家庭",
  project_items: ["防滑处理", "高差处理"],
  project_other: "其他内容",
  street_result: 1,
  civil_result: 1,
});

const option = ref(userAddOption);

const handleSubmit = (form: any, done: Function) => {
  UserAPI.add(form).then(() => {
    ElMessage.success("保存成功");
    done();
    // 返回到列表页面
    router.back();
  });
};

onMounted(() => {});
</script>

<style lang="scss" scoped></style>
